package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyTag;
import cn.wolfcode.luowowo.article.mapper.StrategyTagMapper;
import cn.wolfcode.luowowo.article.service.IStrategyTagService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class StrategyTagServiceImpl implements IStrategyTagService {
    @Autowired
    private StrategyTagMapper tagMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(tagMapper.selectForList(qo));
    }

    @Override
    public void saveByString(String tags) {
        String[] array = tags.split(",");
        //先判断tag表中是否存在了
        for (String s : array) {
            if (tagMapper.selectByName(s) == null){
                tagMapper.insert(s);
            }
        }
    }

    @Override
    public String selectTagsAsStringByDetailId(Long id) {
        return tagMapper.selectNameByDetailId(id);
    }

    @Override
    public List<StrategyTag> selectTagsByDestId(Long destId) {
        return tagMapper.selectTagsByDestId(destId);
    }
}
